css: Handle 'currentColor' special value
authorBenjamin Otte <otte@redhat.com>
Tue, 3 Jan 2012 03:38:09 +0000 (04:38 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 9 Jan 2012 17:37:57 +0000 (18:37 +0100)
Computes to the value of the 'color' property, or when used on that
property, is treated as 'inherit'.

gtk/gtkcssstylefuncs.c
gtk/gtkcssstylepropertyimpl.c

index af1ad5c708d2e7456a6e16fa0e55e141ff7dadcb..7b53bbb73698012891caee6f345cd4fe0c3b9c23 100644 (file)
@@ -173,6 +173,14 @@ rgba_value_parse (GtkCssParser *parser,
   GtkSymbolicColor *symbolic;
   GdkRGBA rgba;
 
+  if (_gtk_css_parser_try (parser, "currentcolor", TRUE))
+    {
+      g_value_unset (value);
+      g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
+      g_value_set_enum (value, GTK_CSS_CURRENT_COLOR);
+      return TRUE;
+    }
+
   symbolic = _gtk_css_parser_read_symbolic_color (parser);
   if (symbolic == NULL)
     return FALSE;
@@ -215,7 +223,12 @@ rgba_value_compute (GValue          *computed,
 {
   GdkRGBA rgba, white = { 1, 1, 1, 1 };
 
-  if (G_VALUE_HOLDS (specified, GTK_TYPE_SYMBOLIC_COLOR))
+  if (G_VALUE_HOLDS (specified, GTK_TYPE_CSS_SPECIAL_VALUE))
+    {
+      g_assert (g_value_get_enum (specified) == GTK_CSS_CURRENT_COLOR);
+      g_value_copy (_gtk_style_context_peek_property (context, "color"), computed);
+    }
+  else if (G_VALUE_HOLDS (specified, GTK_TYPE_SYMBOLIC_COLOR))
     {
       if (_gtk_style_context_resolve_color (context,
                                             g_value_get_boxed (specified),
index 2d1ae65d4488878ad3bfe4e004979360ea141e1e..053cafbc28c1150c390199159030c32dbe128364 100644 (file)
 
 /*** REGISTRATION ***/
 
+static void
+color_compute (GtkCssStyleProperty    *property,
+               GValue                 *computed,
+               GtkStyleContext        *context,
+               const GValue           *specified)
+{
+  g_value_init (computed, GDK_TYPE_RGBA);
+
+  if (G_VALUE_HOLDS (specified, GTK_TYPE_CSS_SPECIAL_VALUE))
+    {
+      GtkStyleContext *parent = gtk_style_context_get_parent (context);
+      g_assert (g_value_get_enum (specified) == GTK_CSS_CURRENT_COLOR);
+
+      if (parent)
+        g_value_copy (_gtk_style_context_peek_property (parent, "color"), computed);
+      else
+        _gtk_css_style_compute_value (computed,
+                                      context,
+                                      _gtk_css_style_property_get_initial_value (property));
+    }
+  else
+    _gtk_css_style_compute_value (computed, context, specified);
+}
+
 static void
 _gtk_style_property_register (const char *                   name,
                               GType                          value_type,
@@ -420,7 +444,7 @@ _gtk_css_style_property_init_properties (void)
                                           GTK_STYLE_PROPERTY_INHERIT,
                                           NULL,
                                           NULL,
-                                          NULL,
+                                          color_compute,
                                           &rgba);
   gtk_style_property_register            ("font-size",
                                           G_TYPE_DOUBLE,